package components.editor
{
	import UIFree.controls.uif_popupMenu;
	import UIFree.uif_component;
	
	import classes.c_events;
	
	import components.scanario.elements.c_eventElement;
	
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class c_elemMenu extends uif_popupMenu {
		public function c_elemMenu(parent:uif_component, options:Object, a_width:int=0, a_height:int=0, styleClass:String='') {
			super(parent, options, a_width, a_height, styleClass);
		}
		
		protected function get dragRect(): c_dragRect {
			return activeControl as c_dragRect;
		}
		
		override protected function listenEvents():void {
			super.listenEvents();
			addEvent(c_events.CHANGECURHOLE, doChangeCurrentHole, cl.workspace);			
		}
		
		public function get cl(): collages {
			return app as collages;
		}
		
		private function doChangeCurrentHole(e: Object): void {
			updateMenuPosition();
		}
		
		override protected function updateMenuPosition(): void {
			if (dragRect.link is c_holeyElement) {
				var he: c_holeyElement = (dragRect.link as c_holeyElement);
				var hole: Object = he.getHole(he.curHole);
				var b: Rectangle = hole.mask.getBounds(dragRect.cl.popupMenuLayer);
				position = new Point(b.left, b.bottom);
			} else super.updateMenuPosition();
		}
	}
}